
// ==================== src/App.tsx ====================
import React, { useEffect } from 'react';
import { RouterProvider } from 'react-router-dom';
import { App as AntApp, ConfigProvider } from 'antd';
import { router } from './router';
import { useUIStore } from './stores/uiStore';
import { useKeyboard } from './hooks/useKeyboard';
import ErrorBoundary from './components/ErrorBoundary/ErrorBoundary';
import { requestNotificationPermission } from './utils/notification';
import './App.css';

const App: React.FC = () => {
  const { theme: appTheme } = useUIStore();

  // 初始化
  useEffect(() => {
    // 请求系统通知权限
    requestNotificationPermission();

    // 监听 Electron 导航事件（如果在 Electron 环境中）
    if (window.electronAPI) {
      window.electronAPI.onNavigate((path: string) => {
        window.location.href = path;
      });
    }

    // 打印启动信息
    console.log('🚀 VirtManager Web Started');
    console.log('Environment:', import.meta.env.MODE);
  }, []);

  // 全局快捷键
  useKeyboard([
    {
      key: 'k',
      ctrl: true,
      handler: (e) => {
        e.preventDefault();
        // 打开快速搜索（可以实现一个命令面板）
        console.log('Quick search triggered');
      },
    },
  ]);

  return (
    <ErrorBoundary>
      <AntApp>
        <ConfigProvider
          theme={{
            algorithm: appTheme === 'dark' ? undefined : undefined,
          }}
        >
          <RouterProvider router={router} />
        </ConfigProvider>
      </AntApp>
    </ErrorBoundary>
  );
};

export default App;